(function ($) {
  // Draw Games Cards mobile collapse

  var onResize = function () {
    if ($(window).width() < 768) {
      if ($('body').hasClass('draw-games-page')) {
        $('.draw-cards .card .collapse').removeClass('show');
        $('.btn-card-collapse').attr('aria-expanded', 'false');
        $('.card.powerball .collapse').addClass('show');
        $('.btn-card-collapse').addClass('collapsed');
        $('.card.powerball .btn-card-collapse').removeClass('collapsed');
        $('.card.powerball .btn-card-collapse').attr('aria-expanded', 'true');

        if ($('.draw-cards .card .collapse').hasClass('show')) {
          $('.draw-cards .card .fas.fa-minus').removeClass('fa-minus').addClass('fa-plus');
          $('.card.powerball .fas.fa-plus').removeClass('fa-plus').addClass('fa-minus');
        } else {
          $('.draw-cards .card .fas.fa-plus').removeClass('fa-plus').addClass('fa-minus');
        }
      }

      $('.btn-card-collapse').on('click', function () {
        if (!$(this).hasClass('collapsed')) {
          $(this).children('.fas.fa-minus').removeClass('fa-minus').addClass('fa-plus');
          var target = $($(this).attr('data-target')).parent();
          $(target).focus();
        } else {
          $(this).children('.fas.fa-plus').removeClass('fa-plus').addClass('fa-minus');
        }
      });
    } else {
      $('.draw-cards .card .collapse').addClass('show');
    }
  };

  $(document).ready(onResize);

  // Only resize on width (to prevent collapsable click from calling onResize)
  var windowWidth = $(window).width();

  $(window).on('resize', function() {
    if ($(this).width() != windowWidth) {
      windowWidth = $(this).width();
      onResize();
    }
  });


/*
  $(document).ready(function () {
    // var moment = require('moment');
    var hotspotCard = $('.card.hotspot').length;
    if (hotspotCard) {
      //Perform Ajax request.
      $.ajax({
        url: '/api/v1.5/drawgames/22?drawscount=1',
        type: 'get',
        dataType: 'json', //json data type
        data: {},
        success: function (data) {
          //If the success function is execute,
          //then the Ajax request was successful.
          //Add the data we received in our Ajax
          //request to the "content" div.
          console.log(data);
          $('.hotspot .date-time').html(moment(data.draws[0].DrawCloseTime).format('ddd/MMM DD, YYYY - h:mm a'));
          $('.hotspot .draw-cards--draw-number').html("Draw # " + data.draws[0].DrawNumber);
        },
        error: function (xhr, ajaxOptions, thrownError) {
          var errorMsg = 'Ajax request failed: ' + xhr.responseText;
          console.log('failure');
        }
      });
    }
  });*/
})(jQuery);